package com.example.consumer.consume;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author shuc001
 * @Date 2018/9/27 下午4:32
 */
@Configuration
public class RabbitmqConfig {

    /**
     * 配置过期队列转发到dlx
     * @return
     */


    @Bean
    public Queue ttlQueue(){
        //params.put("x-message-ttl", 5 * 1000); 这样不太灵活,可以再调用发送函数的时候指定时间
        HashMap<String, Object> properties = new HashMap<>();
        properties.put("x-dead-letter-exchange","dlx_ex");
        properties.put("x-dead-letter-routing-key","dlx.dead");
        return new Queue("ttl_q", true,false,false,properties);
    }

    @Bean
    public DirectExchange ttlExchange(){
        return new DirectExchange("ttl_ex");
    }

    @Bean
    public Binding ttlBinding(){
        return BindingBuilder.bind(ttlQueue()).to(ttlExchange()).with("ttl.#");
    }
}
